home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / time / ialloc.c < prev    next >
C/C++ Source or Header  |  1993-12-02  |  2KB  |  104 lines

  1. #ifndef lint
  2. #ifndef NOID
  3. static char    elsieid[] = "@(#)ialloc.c    8.21";
  4. #endif /* !defined NOID */
  5. #endif /* !defined lint */
  6.  
  7. /*LINTLIBRARY*/
  8.  
  9. #include "private.h"
  10.  
  11. #ifdef MAL
  12. #define NULLMAL(x)    ((x) == NULL || (x) == MAL)
  13. #endif /* defined MAL */
  14. #ifndef MAL
  15. #define NULLMAL(x)    ((x) == NULL)
  16. #endif /* !defined MAL */
  17.  
  18. #define nonzero(n)    (((n) == 0) ? 1 : (n))
  19.  
  20. char *    icalloc P((int nelem, int elsize));
  21. char *    icatalloc P((char * old, const char * new));
  22. char *    icpyalloc P((const char * string));
  23. char *    imalloc P((int n));
  24. char *    irealloc P((char * pointer, int size));
  25. void    ifree P((char * pointer));
  26.  
  27. char *
  28. imalloc(n)
  29. const int    n;
  30. {
  31. #ifdef MAL
  32.     register char *    result;
  33.  
  34.     result = malloc((alloc_size_t) nonzero(n));
  35.     return NULLMAL(result) ? NULL : result;
  36. #endif /* defined MAL */
  37. #ifndef MAL
  38.     return malloc((alloc_size_t) nonzero(n));
  39. #endif /* !defined MAL */
  40. }
  41.  
  42. char *
  43. icalloc(nelem, elsize)
  44. int    nelem;
  45. int    elsize;
  46. {
  47.     if (nelem == 0 || elsize == 0)
  48.         nelem = elsize = 1;
  49.     return calloc((alloc_size_t) nelem, (alloc_size_t) elsize);
  50. }
  51.  
  52. char *
  53. irealloc(pointer, size)
  54. char * const    pointer;
  55. const int    size;
  56. {
  57.     if (NULLMAL(pointer))
  58.         return imalloc(size);
  59.     return realloc((genericptr_t) pointer, (alloc_size_t) nonzero(size));
  60. }
  61.  
  62. char *
  63. icatalloc(old, new)
  64. char * const        old;
  65. const char * const    new;
  66. {
  67.     register char *    result;
  68.     register int    oldsize, newsize;
  69.  
  70.     newsize = NULLMAL(new) ? 0 : strlen(new);
  71.     if (NULLMAL(old))
  72.         oldsize = 0;
  73.     else if (newsize == 0)
  74.         return old;
  75.     else    oldsize = strlen(old);
  76.     if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
  77.         if (!NULLMAL(new))
  78.             (void) strcpy(result + oldsize, new);
  79.     return result;
  80. }
  81.  
  82. char *
  83. icpyalloc(string)
  84. const char * const    string;
  85. {
  86.     return icatalloc((char *) NULL, string);
  87. }
  88.  
  89. void
  90. ifree(p)
  91. char * const    p;
  92. {
  93.     if (!NULLMAL(p))
  94.         (void) free(p);
  95. }
  96.  
  97. void
  98. icfree(p)
  99. char * const    p;
  100. {
  101.     if (!NULLMAL(p))
  102.         (void) free(p);
  103. }
  104.